<template>
    <div>
        <van-nav-bar title="我的订单" left-arrow @click-left="backSup"></van-nav-bar>
        <van-tabs
                class="order-tab"
                v-model="active"
                title-active-color="FBA86"
                color="#FBA86"
                @click="changeStatus"
        >
            <van-tab title="全部"></van-tab>
            <van-tab title="待付款"></van-tab>
            <van-tab title="待发货"></van-tab>
            <van-tab title="待收货"></van-tab>
            <van-tab title="已收货"></van-tab>

            <div v-for="item in orderList" :key="item.orderDeliveryId">
                <div class="order-header">
                    <p>创建时间：{{item.createTime}}</p>
                    <span>{{item.statusDesc}}</span>
                </div>
                <div
                        class="cart-goods-item"
                        v-for="(good,index) in item.deliveryItem"
                        :key="index"
                >
                    <div class="pd-images">
                        <img :src="good.goodsImage" alt/>
                    </div>
                    <div class="pd-info">
                        <div class="pd-title">{{good.goodsName}}</div>
                        <div class="pd-price">
                            <div class="total">
                                <span>邮费：&yen;</span>
                                {{item.postage}}
                            </div>
                            <span class="num">×{{good.quantity}}</span>
                        </div>
                    </div>
                </div>
                <div class="order-bottom">
                    <p>
                        共{{item.deliveryItem.length}}件商品
                        <!-- 合计 ¥{{item.total_price}} -->
                    </p>
                    <p>订单号：{{item.orderNo}}</p>
                    <ul class="order-btn">
                        <li v-if="item.status == 10" @click="payment(item.orderNo,item.postage)">去付款</li>
                        <!--                        <li v-if="item.order_state == 1" @click="cancelConfirm(item.ordersId)">取消订单</li>-->
                        <li v-if="item.status == 30" @click="receipt(item.orderDeliveryId)">确认收货</li>
                        <!-- <li
                                v-if="item.status == 30"
                                @click="toLogistics(item.transportCompany,item.transportNo)"
                        >
                            查看物流
                        </li> -->
                        <li v-if="item.status == 30" @click="getLogistics(item.orderNo)">查看物流</li>
                        <!--  <li v-if="item.order_state == 4" @click="toPublish(item.ordersId)">评价</li>
                        <li v-if="item.order_state >=5" @click="deleteConfirm(item.ordersId)">删除</li>-->
                    </ul>
                </div>
            </div>
            <div v-if="orderList.length==0" class="none">
                <img src="../../assets/imgList/none.jpg"/>
                <p>这里什么也没有</p>
            </div>
        </van-tabs>
        <!-- 展示弹出框 ,用于显示物流信息列表-->
        <van-popup v-model="stepShow" class="logisticsList">
                <div class="logisticsListHead">
                    <p>物流信息</p>
                </div>
                <van-steps direction="vertical" :stepActive="0">
                    <van-step v-for="(item , index) in steplist" :key="index">
                        <p>{{item.AcceptStation}}</p>
                        <p>{{item.AcceptTime}}</p>
                    </van-step>
                </van-steps>
                <div class="logisticsListFooter" @click="stepShow = false">
                    <p>确认</p>
                </div>
        </van-popup>
    </div>
</template>

<script>
    import {Cell, Row, Col, List, Card, Tabs, Tab, Toast, Tag , Popup , Step, Steps} from "vant";
    import api from "@/utils/restful";

    export default {
        components: {
            [Cell.name]: Cell,
            [Row.name]: Row,
            [Col.name]: Col,
            [List.name]: List,
            [Card.name]: Card,
            [Tabs.name]: Tabs,
            [Tab.name]: Tab,
            [Toast.name]: Toast,
            [Tag.name]: Tag,
            [Popup.name]: Popup,
            [Step.name]: Step,
            [Steps.name]: Steps,
        },
        data() {
            return {
                active: 0,
                orderList: [],
                orderInfo: {},
                stepActive: 0,
                stepShow: false,
                steplist: [],
            };
        },
        created() {
            this.active =this.$route.params.vipstate || sessionStorage.getItem("vipstate") || "0";
            this.getOrder()
        },
        mounted() {
            this.initGetOrder();
        },
        methods: {
            initGetOrder() {
                sessionStorage.setItem("vipstate", this.active);
                this.getOrder(this.active);
            },
            changeStatus(index, title) {
                this.initGetOrder();
            },
            // 获取全部订单
            getOrder(order_state = -1) {
                console.log(order_state);
                if (order_state === 0) {
                    order_state = -1;
                } else if (order_state === 1) {
                    order_state = 10;
                } else if (order_state === 2) {
                    order_state = 20;
                } else if (order_state === 3) {
                    order_state = 30;
                } else if (order_state === 4) {
                    order_state = 40;
                }
                this.$axios({
                    method: "get",
                    url: api.deliveryOrderList,
                    params: {
                        token: localStorage.getItem("token"),
                        status: order_state
                    }
                }).then(res => {
                    console.log(res.data);
                    this.orderList = res.data;
                });
            },
            payment(ordersId, paymentPrice) {
                console.log(ordersId);
                this.orderInfo.id = ordersId;
                this.orderInfo.paymentPrice = paymentPrice;
                this.orderInfo.returnUrl = "viporder";
                this.$router.push({
                    name: "OnlinePay",
                    params: {orderInfo: this.orderInfo}
                });

            },

            receipt(ordersId) {
                this.$axios({
                    method: "post",
                    url: api.confirmReceive,
                    data: this.$qs.stringify({
                        ordersId: ordersId,
                        token: localStorage.getItem("token")
                    })
                }).then(res => {
                    console.log(res);
                    this.initGetOrder();
                });
            },
            backSup() {
                this.$router.push({name: "vip"});
            },
            toOrderDetail(ordersId) {
                this.$router.push({
                    name: "orderdetail",
                    query: {ordersId: ordersId}
                });
            },
            /* 获取订单物流信息 */
            getLogistics(id) {
                /* 请求物流信息地址 */
                this.$axios({
                    method: "post",
                    url: api.shippingInfo,
                    data: this.$qs.stringify({
                        orderNo: id,
                        token: localStorage.getItem("token")
                    })
                }).then(res => {
                    console.log(res);
                    this.steplist = [...res.data.shippingInfo]
                    this.stepShow = true;
                });
            },
            /* toLogistics(transportCompany, transportNo) {
                console.log(this.orderList)
                this.$dialog
                    .confirm({
                        title: "查看物流",
                        message: `${transportCompany}<br>${transportNo}`,
                        closeOnClickOverlay: true,
                        showCancelButton: false
                    })
                    .then(() => {
                        this.cancel(ordersId);
                    })
                    .catch(() => {
                    });
                //   this.$router.push({
                //     name: "logistics",
                //     query: { ordersId: ordersId }
                //   });
            }, */
            toPublish(ordersId) {
                this.$router.push({name: "publish", query: {ordersId: ordersId}});
            }
        }
    };
</script>

<style lang="less" scoped>
    @import "~style/common.less";

    .order-header {
        display: flex;
        padding: 15px;
        padding-bottom: 0;
        background-color: #fff;
        border-top: 1px solid #eee;
        justify-content: space-between;
        .font-dpr(12px);

        span {
            color: @priColor;
        }
    }

    .order-bottom {
        padding: 15px;
        background-color: #fff;
        text-align: right;
        .font-dpr(12px);

        .order-btn {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            background-color: #fff;
            height: 44px;

            li {
                .font-dpr(12px);
                // border:1Px solid @priColor;
                line-height: 24px;
                height: 24px;
                border-radius: 12px;
                padding: 0 8px;
                margin-left: 10px;
                color: @tipColor;

                &:nth-child(1) {
                    color: @priColor;
                    border: 1px solid @priColor;
                }

                &:nth-child(2) {
                    // color: @tipColor;
                    border: 1px solid @tipColor;
                }
            }
        }
    }

    .cart-goods-item {
        background-color: #fff;
        // margin-top: 10px;
        // width: 90vw;
        padding: 10px 15px;
        // border: 1px solid #f9f;
        .flexbox(flex-start, center, row, nowrap);
        justify-content: space-between;
        // padding: 5px;
        // border-bottom: 1px solid @borderColor;
        &:last-child {
            border-bottom: none;
        }

        .order-info {
            border: 1px solid red;
            position: relative;
            margin-top: 10px;
            padding: 17px 25px;
            color: @fontColorH3;
            .font-dpr(14px);
            font-weight: normal;
            background-color: #fff;

            &::after {
                position: absolute;
                content: "";
                display: block;
                width: 3px;
                height: 14px;
                left: 15px;
                top: 21px;
                background-color: @priColor;
            }

            p {
                .font-dpr(12px);
                color: @fontColorP;
                font-weight: 300;
                margin-top: 12px;
            }
        }

        .pd-images {
            border: 1px solid @borderColor;
            // border: 1px solid #f0f;

            margin: 0 15px 0 5px;
            flex: 1;
            // max-width: 100px;
            img {
                width: 75px;
                height: 75px;
            }
        }

        .pd-info {
            flex: 3;
            // .flexbox(flex-start, space-between, column, wrap);
            -width: 68% !important;
            // flex: initial;
            // border: 1px solid blue;

            .pd-title {
                position: relative;
                text-overflow: ellipsis;
                overflow: hidden;
                display: -webkit-box;
                /* autoprefixer: off */
                -webkit-box-orient: vertical;
                /* autoprefixer: on */
                -webkit-line-clamp: 2;

                max-width: 100%;
                .font-dpr(12px);
                color: @fontColorH3;
            }

            .pd-sku {
                padding: 5px 0;
                line-height: 1.5;
                .font-dpr(11px);
                color: @tipColor;
            }

            .pd-price {
                margin-top: 10px;

                .total {
                    .font-dpr(14px);
                    color: @secColor;
                }

                .flexbox(space-between, center, row, nowrap);
                flex: initial;

                /deep/ .van-stepper {
                    // z-index: 999;
                    .flexbox(space-between, center, row, nowrap);
                    flex: initial;
                    border-radius: 2px;
                    // border: 1px solid #f0f;
                    max-height: 16px;
                    width: 2rem;

                    .van-stepper__minus,
                    .van-stepper__plus {
                        border: none;
                        max-height: 16px;
                        background-color: @bgColor;
                    }

                    .van-stepper__input {
                        border: 1px solid @borderColor;
                        // border: 1px solid #f00;
                        max-height: 16px;
                        background-color: @bgColor;
                        // border: none;
                        outline: none;
                        text-align: center;
                        padding: 0;
                        min-width: 40%;
                        .font-dpr(11px);
                    }

                    .van-stepper__minus--disabled {
                        background-color: @bgColor;
                    }
                }
            }

            .num {
                .font-dpr(12px);
            }
        }
    }

    .none {
        height: calc(100vh - 90px);
        box-sizing: border-box;
        padding-top: 100px;
        text-align: center;

        img {
            width: 200px;
            height: 200px;
        }

        p {
            margin-top: 20px;
            padding: 15px 0;
            font-size: 16px;
            color: #999;
        }
    }
    .logisticsList {
        width: 80%;
        height: 400px;
        overflow: scroll;
        .logisticsListHead {
            font-size: 16px;
            text-align: center;
            border-bottom: 1px solid #f5f5f5;
            padding: 8px 0;
        }
        .logisticsListFooter {
            width: 100%;
            font-size: 16px;
            text-align: center;
            border-top: 1px solid #f5f5f5;
            background-color: #fff;
            padding: 8px 0;
        }
    }
</style>

